package Tk02;

import java.util.ArrayList;
import java.util.Iterator;

public class Test {
    public static void main(String arg[]){

        ArrayList<Student>arr=new ArrayList<>();

        Student xm=new Student("小明","12345",20);
        Student xh=new Student("小红","56496",18);
        Student xl=new Student("小亮","56496",19);

        arr.add(xm);
        arr.add(xh);
        arr.add(xl);

        arr.add(2,new Student("小军","5467",25));

        arr.remove(0);

        for(Student student:arr){
            System.out.println(student.getName()+" "+student.getId()+" "+student.getAge());
        }

        Iterator<Student> it = arr.iterator(); // 创建迭代器

        while (it.hasNext()) { // 检查是否有更多的元素可以遍历
            Student student = it.next(); // 获取下一个元素
            System.out.println(student.getName()+" "+student.getId()+" "+student.getAge());
        }
    }
}
